<?php
//%CB%F9%D3%D0%B7%D6%C0%E0
//header("Content-type: text/html; charset=utf-8");
$url='http://search.taobao.com/search?q='.urlencode(mb_convert_encoding($keyword,'gbk','utf-8')).'&style=list&s=0';
//http://search.taobao.com/search?q=iphone&style=list&s=0
//header("Content-type: text/html; charset=gbk");
//var_dump($url);
//var_dump(file_get_contents($url));

$content=get_html($url);
$patten="/<li class=\"list-item\">(([\t   ]*\r\n.*)|(.*))<h3 class=\"summary\"><a stat=\"(.*)\" href=\"(.*)\" target=\"_blank\" class=\"EventCanSelect\" title=\"(.*)\">(.*)<\/a><\/h3>(([\t   ]*\r\n.*)|(.*))<div class=\"photo\">(([\t   ]*\r\n.*)|(.*))<a(.*)><span><img data-lazyload-src=\"(.*)\" class=\"(.*)\" \/><\/span><\/a>(([\t   ]*\r\n.*)|(.*))<\/div>(([\t   ]*\r\n.*)|(.*))<ul class=\"attribute\">(([\t   ]*\r\n.*)|(.*))<li class=\"legend2\">(([\t   ]*\r\n.*)|(.*))<a(.*)<\/a>(([\t   ]*\r\n.*)|(.*))<\/li>(([\t   ]*\r\n.*)|(.*))<li (.*)<\/li>(([\t   ]*\r\n.*)|(.*))<li class=\"place\">(.*)<\/li>(([\t   ]*\r\n.*)|(.*))<li class=\"price\"><em>(.*)<\/em>/i";
preg_match_all($patten,$content,$items,PREG_SET_ORDER);
foreach ($items as $key=>$val){
	$data['items'][$key]['type']=SEARCH_TAOBAO;
	$data['items'][$key]['url']=trim(mb_convert_encoding($val[5],'utf-8','gbk'));
	$data['items'][$key]['title']=trim(mb_convert_encoding($val[6],'utf-8','gbk'));
	$data['items'][$key]['icon']=trim(mb_convert_encoding($val[15],'utf-8','gbk'));
	$pos=strpos($val[40],'<a');
	if($pos){
		$addr=substr($val[40],0,$pos);
	}else{
		$addr=$val[40];
	}
	unset($pos);
	$data['items'][$key]['addr']=trim(mb_convert_encoding($addr,'utf-8','gbk'));
	unset($addr);
	$data['items'][$key]['price']=$val[44];
}
unset($url);
unset($content);
unset($patten);
unset($items);
tm_template('search.html','shoppingbox');

/*header('Content-Type: text/xml;');
$dom=new DOMDocument('1.0', 'utf-8');
$items=$dom->createElement('Items');
$dom->appendChild($items);
foreach ($data as $key=>$val){
	$item=$dom->createElement('Item');
	
	$url=$dom->createElement('Url');
	$urlText=$dom->createTextNode($val['url']);
	$url->appendChild($urlText);
	$item->appendChild($url);
	
	$title=$dom->createElement('Title');
	$titleText=$dom->createTextNode($val['title']);
	$title->appendChild($titleText);
	$item->appendChild($title);
	
	$icon=$dom->createElement('Icon');
	$iconText=$dom->createTextNode($val['icon']);
	$icon->appendChild($iconText);
	$item->appendChild($icon);
	
	$addr=$dom->createElement('Addr');
	$addrText=$dom->createTextNode($val['addr']);
	$addr->appendChild($addrText);
	$item->appendChild($addr);
	
	$items->appendChild($item);
}
$xml=$dom->saveXML();
echo $xml;*/

//标题 图片 价格 城市 来源
?>